<?php
/**
 * @author: Đặng Văn Trường
 * @since: 22/07/2014
 * @todo : Model Auto Increment
 */
class Module_Models_Increment extends Zend_Db_Table {	
	
	protected $_name="increment";
    protected $_primary="ID";
    protected $_primary_name="ID";
    
    public function getNumber($year,$type){
        $query = "SELECT Number FROM $this->_name WHERE Years='$year' And Type='$type'";
        $result = $this->getAdapter()->fetchRow($query);
        if ($result) {
            $number = $result['Number'];
        }else{
            $arrInput = array(
                    'Years'=>$year
                    ,'Number'=>1
                    ,'Type'=>$type
                );
            // var_dump($arrInput); die;
            $this->insert($arrInput);
            $number = 1;
        }
        return $number;
    }

}
?>
